"""
URL configuration for Django_demo01 project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include, re_path
from django.shortcuts import HttpResponse
from django.views.generic import RedirectView
from django.views.static import serve


def index(request):
    return HttpResponse("欢迎你，login")


urlpatterns = [
    path("admin/", admin.site.urls),
    path("index/", index),
    # 正则路由(re_path)，配置媒体文件路由地址 （以media开头的请求都转发到 settings.MEDIA_ROOT下）
    re_path(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT}, name="media"),
    path("book/", include(("sys_book.urls", "sys_book"), namespace="sys_book")),
    path("auth/", include("user_auth.urls")),
    path("type/", include("sys_book.urls")),

    # 请求重定向，api请求重定向到 book请求
    path("api/", RedirectView.as_view(url="book/"))
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS[0])
